package com.ruanmou.spring.demo;

import com.ruanmou.spring.demo.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestIOC {
    public static void main(String[] args) {
        // 注意：从spring容器中获取的对象默认为单列对象
        // 实例化了一个Spring容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = (UserService) context.getBean("userService");
        UserService userService1 = (UserService) context.getBean("userService");
        System.out.println(userService == userService1); // true
        userService.register();
    }
}
